Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invert canvas rotation direction if view is flipped #1778

Merged
merged 6 commits into from
Aug 8, 2023

Conversation

HeCorr
Copy link
Contributor

@HeCorr HeCorr commented Aug 3, 2023

Fixes #1777.

Please note that I am not an experienced C++ developer, so please let me know if something can be improved!

This PR adds a check to ActionCommands::rotateClockwise(), ActionCommands::rotateCounterClockwise() and HandTool::transformView() that inverts the rotation direction if the view is flipped either horizontally or vertically (but not both), so it's more intuitive:

Shortcuts (Z then R):
https://github.com/pencil2d/pencil/assets/75134774/ac722475-312d-4ac9-aeee-42c81653dcd6

Hand Tool:
https://github.com/pencil2d/pencil/assets/75134774/5e6d216b-31dd-4e88-844d-06c87b3a86c9

Copy link
Member

@MrStevns MrStevns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Henrique

Thanks again for contributing 😄

I have a few things this time around, although the code itself is fine, I think we can do a better than simply copy/pasting, which could introduce bugs down the line.

There's also the usage of bitwise XOR, which is not something we use in the project afaik. I don't personally have a stance on that as I think there's something to be said about its simplicity but it could introduce bugs... as such I think it may be better to use conventional logical operators instead, like:
if (A && !B || B && !A)

Note: Don't feel disheartened by the lack of approval right away, there's nothing wrong with the code, it just needs a bit of tweaking. We strive for simple and readable while also trying to minimize the possibility of bugs.

app/src/actioncommands.cpp Outdated Show resolved Hide resolved
app/src/actioncommands.cpp Outdated Show resolved Hide resolved
core_lib/src/tool/handtool.cpp Outdated Show resolved Hide resolved
similar to `rotate()` but doesn't require caller to know the current view rotation.
- replace XOR operators with `A == !B`
- replace `if` with ternary operator
- use rotateRelative() instead of rotate()
- define a delta constant and call rotateRelative() once
- replace `if` with ternary operator
- replace rotate() with rotateRelative()
@HeCorr
Copy link
Contributor Author

HeCorr commented Aug 7, 2023

Apologies for the delay in committing the last changes, I've made some improvements and re-tested everything. :)

Please review once again!

Copy link
Member

@MrStevns MrStevns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes looks good to me, no further comments.

Good job 👍

@MrStevns MrStevns merged commit 7b0f120 into pencil2d:master Aug 8, 2023
4 checks passed
@HeCorr HeCorr deleted the view-rotation-fix branch August 8, 2023 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Counterintuitive canvas rotation when view is flipped
4 participants